<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author lzw
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <a-button type="primary" @click="handleForm({})" v-auth="'operating:ftdsZwrcl:edit'">
          <Icon icon="i-fluent:add-12-filled" /> {{ t('新增') }}
        </a-button>
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ id: record.id })">
          {{ record.zwrclSjly }}
        </a>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup name="ViewsOperatingFtdsZwrclList">
  import { unref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { ftdsZwrclDelete, ftdsZwrclListData } from '/@/api/operating/ftdsZwrcl';
  import { ftdsZwrclDisable, ftdsZwrclEnable } from '/@/api/operating/ftdsZwrcl';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';

  const { t } = useI18n('operating.ftdsZwrcl');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('债务人材料管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('数据来源'),
        field: 'zwrclSjly',
        component: 'Input',
      },
      {
        label: t('文件名称'),
        field: 'zwrclWjmc',
        component: 'Input',
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('数据来源'),
      dataIndex: 'zwrclSjly',
      key: 'a.zwrcl_sjly',
      sorter: true,
      width: 230,
      align: 'left',
      slot: 'firstColumn',
    },
    {
      title: t('文件名称'),
      dataIndex: 'zwrclWjmc',
      key: 'a.zwrcl_wjmc',
      sorter: true,
      width: 130,
      align: 'left',
    },
  ];

  const actionColumn: BasicColumn = {
    width: 160,
    actions: (record: Recordable) => [
      {
        icon: 'i-simple-line-icons:arrow-down-circle',
        color: 'success',
        title: t('下载债务人材料'),
        popConfirm: {
          title: t('请确认是否下载债务人材料'),
          confirm: handleEnable.bind(this, record),
        },
        auth: 'operating:ftdsZwrcl:edit',
      },
    ],
  };

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload }] = useTable({
    api: ftdsZwrclListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  // async function handleDisable(record: Recordable) {
  //   const params = { id: record.id };
  //   const res = await ftdsZwrclDisable(params);
  //   showMessage(res.message);
  //   handleSuccess(record);
  // }

  async function handleEnable(record: Recordable) {
    const params = { id: record.id };
    await ftdsZwrclEnable(params);
    handleSuccess(record);
  }
  // async function handleEnable(record: Recordable) {
  //   const { ctxAdminPath } = useGlobSetting();
  //   downloadByUrl({ url: ctxAdminPath + '/operating/fstCase/importGjTemplate?path=',record.id });
  // }
  // async function handleDelete(record: Recordable) {
  //   const params = { id: record.id };
  //   const res = await ftdsZwrclDelete(params);
  //   showMessage(res.message);
  //   handleSuccess(record);
  // }

  function handleSuccess(record: Recordable) {
    reload({ record });
  }
</script>
